import request from "@/utils/request";

const STOCKRECEIVABLE_BASE_URL = "/api/v1/stockReceivables";

const StockReceivableAPI = {
  /** 获取应收分页数据 */
  getPage(queryParams?: StockReceivablePageQuery) {
    return request<any, PageResult<StockReceivablePageVO[]>>({
      url: `${STOCKRECEIVABLE_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /**
   * 获取应收表单数据
   *
   * @param id 应收ID
   * @returns 应收表单数据
   */
  getFormData(id: number) {
    return request<any, StockReceivableForm>({
      url: `${STOCKRECEIVABLE_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /** 添加应收*/
  add(data: StockReceivableForm) {
    return request({
      url: `${STOCKRECEIVABLE_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 更新应收
   *
   * @param id 应收ID
   * @param data 应收表单数据
   */
  update(id: number, data: StockReceivableForm) {
    return request({
      url: `${STOCKRECEIVABLE_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 批量删除应收，多个以英文逗号(,)分割
   *
   * @param ids 应收ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${STOCKRECEIVABLE_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};

export default StockReceivableAPI;

/** 应收分页查询参数 */
export interface StockReceivablePageQuery extends PageQuery {
  /** 状态（关联字典编码receivable_status） */
  status?: string;
}

/** 应收表单对象 */
export interface StockReceivableForm {
  /** 主键 */
  id?: number;
  /** 应收说明 */
  description?: string;
  /** 借出方式 */
  outPath?: string;
  /** 金额 */
  amount?: number;
  /** 借出日期 */
  startDate?: Date;
  /** 归还日期 */
  endDate?: Date;
  /** 状态（关联字典编码receivable_status） */
  status?: string;
}

/** 应收分页对象 */
export interface StockReceivablePageVO {
  /** 主键 */
  id?: number;
  /** 应收说明 */
  description?: string;
  /** 借出方式 */
  outPath?: string;
  /** 金额 */
  amount?: number;
  /** 借出日期 */
  startDate?: Date;
  /** 归还日期 */
  endDate?: Date;
  /** 状态（关联字典编码receivable_status） */
  status?: string;
}
